/********************************************************
Code to create the predicted probabilities for Figure OE3
using the Pew CNN Data. Also creates the Table for these reults. 
Plotting is done using R. 
***********************************************************/

/**************************
		Data
**************************/

clear
*change directory to "....\Data\"
*cd 
use "pew_cnn_comb.dta"

/**************************
		Cleaning

Some of the labels are not right 
**************************/

**Income
label def inc1 1 "<30,000" 2 "30,000-49,999" 3 "50,000-74,999" 4 "75,000-99,999" 5 "100,000+"
label values income1 inc1
label var income1 "Income"

label def inc2 1 "<30,000" 2 "30,000-49,999" 3 "50,000-74,999" 4 "75,000+"
label values income2 inc2
label var income2 "Income"

**Gender
label def gend 1 "Female" 0 "Male"
label values gender gend
label var gender "Gender"

**Education 
label var educ "Education"
label def edu 1 "<HS" 2 "HS" 3 "Some College" 4 "BA" 5 "Post-BA"
label values educ edu

**Race/Ethnicity
*Remove the 9
recode race_eth (9 = .)
label var race_eth "Race/Ethnicity"
label def rac 1 "White" 2 "Black" 3 "Hispanic" 4 "Other Race"
label values race_eth rac

**Age
label var age "Age"

**Sponsor
encode sponsor, gen(sponsor1)

**Year
label var year "Year of Survey"

**Too Extreme
label var too_extreme1 "Parties Too Extreme?"
label def too1 1 "Neither" 2 "One Too Extreme" 3 "Both Too Extreme"
label values too_extreme1  too1

***PID & Ideol Ext
label var pid_ext "PID Extremity"
label def pext 1 "Independent" 2 "Leaner" 3 "Partisan"
label values pid_ext pext

label var ideol_ext "Ideological Extremity"
label def iext 1 "Moderate" 2 "Liberal/Conservative" 3 "Very Liberal/Conservative"
label values ideol_ext iext

**Too Extreme (no dks)
gen dks = 1 if rep_dk == 0 & dem_dk == 0 

gen tooext_nodk = . 
	replace tooext_nodk = 1 if too_extreme1 == 1 & dks == 1
	replace tooext_nodk = 2 if too_extreme1 == 2 & dks == 1
	replace tooext_nodk = 3 if too_extreme1 == 3 & dks == 1
label var tooext_nodk "Parties Too Extreme?" 
label values tooext_nodk too1
	
     	
/**************************
	Model and Predictions
**************************/

****Without Controls
eststo clear
eststo: gsem (i.tooext_nodk <- i.ideol_ext##c.year S[surveyid]@1) [pweight=weight], mlogit
	
	forval i = 1/3 {
		margins, dydx(year) by(ideol_ext) predict(outcome(`i'.tooext_nodk)) saving(probs_`i'_nocontrol, replace)
	}	
	
esttab using "table_oe1.rtf", replace onecell se aic bic label nobaselevels unstack b(3) ///
	mtitles("Neither" "One Party" "Both Parties") ///
	title("{\b Table OE1:} Ideology x Year Interaction, No DKs (Pew/CNN Data)")


